Introduction
The syntax file (SDF) is the heart of syntax specific capabilities of Twistpad.
All SDF files are located in the sub-folder "Syntax" of the main Twistpad folder.
It's the SDF files which define how a syntax is applied to a particular file (identified by it's extension)
The syntax of the SDF file is very similar to a standard Windows INI file. If you are familiar with this type of file, it should be easier to edit SDF files.
Although a very complex file syntax can be archived in Twistpad, the ease of creation of a new syntax it's one of the many strengths you can find in Twistpad. In 2 minutes you can create a new syntax file, simply based on keywords.
There are 3 main blocks in a SDF file, the [::Header::] which can be only one, and is not optional, and several sets of optional keywords and start-stop sections.
Header section
The header section is required to proper enable syntax for a specific file type in Twistpad.
the header, as in Ini Files is always : [::Header::]
The keywords for the Header section are:
- SyntaxName*: The name of the syntax
- Extensions*: The file extensions where this syntax is applied
- Functions: Regular expression to define functions or sections
- HelpFile: One or more Help files for use with this syntax (multiple can be used with the | sign)
- Spelling: 1 or 0. When 0, means spell nothing, except in the contexts defined in the SpellingContexts keyword, if 1 spell everything except in the contexts defined in the SpellingContexts keyword**
- SpellingContexts: coma delimited contexts, it's use is defined in the Spelling keyword
- SnippetFile: Snippet file to use in the syntax
- Delimiters: custom delimiters for this syntax (please note a space is always considered a delimiter)
Sections
There are two types of sections, Start-Stop Sections and Keywords Section.
Start-Stop Sections define a text color/format for, as the name implies, a block of text with recognized tokens. for instance you could say you want everything that starts with { and ends with } in blue.
Keywords define a single word which is to be colored, for instance, you might want that the word "Blue" appears in blue.
Both have the following Keywords:
- Type*: StartStop or Keyword
- Context*: a unique number that identifies this StartStop ID
- Scope*: Defines a context where this context is active
- Priority*: or importance of this keyword/StartStop, higher numbers means higher priority in displaying the context
- WholeWordOnly*: 1 or 0, if 1 the word separator has to be one of the delimiters, if not the word separators are ignored
- CaseSensitive:1 or 0, Denotes if the StartStop Keys or the Keywords should be treated as case sensitive (1) or not (0)
- BeginParagraph:1 or 0, Denotes if the StartStop Keys or the Keywords should be only activated if they are the first word in a paragraph
- StartOfParagraph:1 or 0, Denotes if the StartStop Keys or the Keywords should be only activated if they start at the beginning of a paragraph
- Background*:Color of the background, in HEX style (use insert color) or Default for default background color
- Foreground*:Color of the foreground, in HEX style (use insert color) or Default for default foreground color
- Bold:0 or 1, to make words in bold
- Italic:0 or 1, to make words in italic
Specific StartStop Keywords
- First: The first word to define the start section
- Last: The last word to define the stop section
- Outline: 0 or 1, defines whether this section can be closed
- Smart: 0 or 1, defines if the stop section is incremented, for example to find a matching pair of { when smart is enabled, any closing sections are ignored if more open sections are found
Specific Keywords Keywords
- Keyword1 to Keyword16:here the Keywords are defined with a ; separating each one you can use.
Example
As a simple example let's say that you wish to have the words
Twistpad,
Syntax and
File in blue.
Also everything from { to } in bold red, and everything inside the brackets you wish that the word
Color be displayed in green.
Point to new file in Twistpad, create the header that should be something like:
[::Header::]
SyntaxName=Test syntax
extensions=tst
Now, as a rule, although this is not required, you should declare the start stop sections first. So we need to declare the brackets section
[Brackets]
Type=StartStop
Context=1
Scope=0
Priority=7
First={
Last=}
Background=Default
Foreground=FF0000
Bold=1
Now on to the keywords
[BlueKeywords]
Type=keyword
Context=100
Scope=0
Priority=6
WholeWordOnly=1
Keyword1=Twistpad;Syntax;File
Background=Default
Foreground=0000FF
[GreenColorOnBrackets]
Type=keyword
Context=101
Scope=1
Priority=6
WholeWordOnly=1
Keyword1=Color
Background=Default
Foreground=008000
Notice the scope set to 1, this is to force the use of this style on the context 1, which is the brackets
Tips
The best way to make a new syntax is to modify an existing one, you can find all syntax definition files in the sub folder "Syntax" of Twistpad main folder.
In the Carthago Software Site, you may find a lot of syntax files, the chances are you will not need to create any SDF file, as someone might already created it!
Notes
* Denotes a required keyword
** Context's are explained in the StartStop and Keywords section
© 1998 - 2006 Carthago Software. All rights reserved.